﻿Imports System.Data.Common

Public Class ServiceManager

  Private _connection As DbConnection
  Private Shared _instance As ServiceManager

  Private _connectiontype As eConnectionType = Configuration.GetObject.DatabaseType

  Private _wallpaperservice As WallpaperService

  Public Enum eConnectionType
    Oracle = 1
    MySQL = 2
    SQLite = 3
  End Enum

  Private Sub New(ByVal connection As DbConnection)
    _connection = connection
  End Sub

  Public Shared ReadOnly Property GetServiceManager(Optional ByVal connection As DbConnection = Nothing, Optional ByVal connectiontyp As eConnectionType = eConnectionType.Oracle) As ServiceManager
    Get
      If ServiceManager._instance Is Nothing Then
        If connection Is Nothing Then
          Throw New Exception("Um den ServiceManager zu instanziiren muss eine gültige Connection übergeben werden.")
        Else
          _instance = New ServiceManager(connection)
        End If
      End If
      Return _instance
    End Get
  End Property

  Public ReadOnly Property GetWallpaperService() As WallpaperService
    Get
      If _wallpaperservice Is Nothing Then
        If _connectiontype = eConnectionType.MySQL Then
          _wallpaperservice = New MySQLWallpaperService(_connection)
        ElseIf _connectiontype = eConnectionType.Oracle Then
          _wallpaperservice = New OracleWallpaperService(_connection)
        ElseIf _connectiontype = eConnectionType.SQLite Then
          _wallpaperservice = New SQLiteWallpaperService(_connection)
        End If
      End If
      Return _wallpaperservice
    End Get
  End Property


End Class
